﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Schedule.aspx.cs" Inherits="TheatreStaff_Schedule" %>
<%@ Register TagPrefix="custom" Namespace="myControls" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Configuration" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script type="text/javascript">
        
        function displayCalendar()
        {
            var datePicker = document.getElementById('datePicker');
            datePicker.style.display = 'block';
        }
</script>
<script runat ="server" >
    protected void btnOk_Click(object sender, EventArgs e)
    {
        srcSchedule.InsertParameters["TheatreId"].DefaultValue = lblId.Text;
        grdSchedule.DataBind();
    }
    protected void dtlSchedule_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        grdSchedule.DataBind();
    }
    protected void dtlSchedule_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
        grdSchedule.DataBind();
    }
    void Page_Load()
    {
        if (!Page.IsPostBack)
            grdSchedule.SelectedIndex = 0;  
    }
</script>
<script type="text/javascript">
function showInsert() {
    var divInsert = document.getElementById('divInsert');
    divInsert.style.display = 'block';
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
</script>
 <style type="text/css">
        #datePicker
        {
            display:none;
            position:absolute;
            border:solid 2px black;
            background-color:white;
           
        }
    
    </style>
<style type="text/css">
.center1
{
    padding-left:320px;
}
.content1
{
    margin:auto;
    width:850px;
}
.column
{
    float:left;
    width:348px;
}
.selectedRow
{
    background-color:Silver;
}
html
{
  background-image:url('image/back.jpg'); 

    padding:10px;
    color:White;    
  
}

.content
{
    width:950px;
    margin:auto;
        height: 197px;
    }

.link
{
  margin-left:350px; 
     font-weight:bold;
  font-size:large;  
    font-size:x-large;
}
.link2
{
  margin-left:50px; 
     font-weight:bold;
  font-size:large;  
    font-size:x-large;
}
a
{
 color: white;
 text-decoration:underline;
 font-weight:bold;

}
a:hover
{
 color: red; 
  text-decoration:none;
  font-weight:bold;

}
.join
{
   background-color:#0099FF;
  clip:auto;
  font-weight:bold;
  font-size:large;
}
.table2
{
 border-style:solid;
   border-color:Black;
   background-color:White;
   color:Black;  
   width:900px; 
}
.row
{
   background-color:Gray;
   color:White;
}
.ticket
{
   background-color:#CC0000;
color:White;

}

.ticket:hover
{
 color: black; 
  text-decoration:none;


}
    .style1
    {
        width: 509px;
    }
    
.footer
{

     font-weight:bold;
  font-size:large;  

}
.ticket1
{
    padding-left:200px;
}
.view2
{
 padding-left:180px;  
}
.text
{
 font-weight:bold;
}
.button
{
 margin-left:250px;
}
.view3
{
    padding-left:120px;
}
.footer
{

   margin-top:250px;
}
.center
{
    padding-left:410px;
}
.cinema
{
    padding-left:590px;
}
     .menu
{
 padding-left:150px;  

}
</style>
    <title>Schedule Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div class="content">
   <asp:Image ID="Image1" Width="1000" Height="130" ImageUrl="~/image/tdk-jun5-bannerbatmanexclusivo2.jpg" runat="server" /><br />
<asp:HyperLink ID="HyperLink14"  CssClass="link" NavigateUrl="~/Default.aspx" runat="server">Home</asp:HyperLink>
<asp:HyperLink ID="HyperLink1"  CssClass="link2" NavigateUrl="~/Session.aspx" runat="server">Session</asp:HyperLink> <asp:HyperLink ID="HyperLink2" CssClass="link2" NavigateUrl="~/Movie.aspx" runat="server">Movies</asp:HyperLink>
<asp:HyperLink ID="HyperLink3" CssClass="link2"  NavigateUrl="~/Price.aspx" runat="server">Prices</asp:HyperLink>
 <br />
 <br />
   <%--<asp:Label ID="Label5" runat="server"  Text="Theatre" CssClass="cinema" Font-Bold="True" Font-Underline="True"></asp:Label>
        <asp:Label ID="Label4" runat="server"  ForeColor="Yellow"></asp:Label>
      
&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp&nbsp;&nbsp &nbsp&nbsp;&nbsp 
          <asp:Label ID="Label3" runat="server" Text="UserName" Font-Bold="True"></asp:Label>    <asp:LoginName ID="LoginName1" runat="server" /> 
    &nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp&nbsp;&nbsp<asp:LoginStatus ID="LoginStatus1" runat="server" ForeColor="#99CCFF" />--%>
<table class="center1" >
        <tr>
            <td>
               <asp:Label ID="Label1111" runat="server" CssClass="menu"  Text="Theatre" Font-Bold="True" Font-Underline="True"></asp:Label>  
            </td>
            <td>
                 <asp:Label ID="Label4" runat="server"  ForeColor="Yellow"></asp:Label>
                 &nbsp;&nbsp;&nbsp;
            </td>
       <%-- </tr>
 </table> --%>
    <%--<td>&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp&nbsp;&nbsp &nbsp&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp&nbsp;&nbsp &nbsp&nbsp;&nbsp</td>--%>
<%--&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp&nbsp;&nbsp&nbsp&nbsp;&nbsp &nbsp&nbsp;&nbsp --%>
  <%--<table align="center" >
        <tr>--%>
            <td>
                <asp:Label ID="Label18" runat="server" Text="UserName" Font-Bold="True"></asp:Label>
                &nbsp;&nbsp;
            </td>
            <td>
                <asp:LoginName ID="LoginName1" runat="server" /> 
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </td>
            <td>
                 <asp:LoginStatus ID="LoginStatus1" runat="server" ForeColor="#99CCFF" />
                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </td>
        </tr>
    </table>
        <hr />
  <asp:Label ID="Label8" runat="server" Text="Maintain:" Font-Bold="True" Font-Size="Larger" Font-Underline="True"></asp:Label>
<asp:HyperLink ID="HyperLink4" runat="server" 
            NavigateUrl="~/TheatreStaff/Cinema.aspx" ForeColor="#FFCC99">[Cinemas]</asp:HyperLink>&nbsp;&nbsp;
    <asp:HyperLink ID="HyperLink5" runat="server"  ForeColor="#FFFF99" NavigateUrl="~/TheatreStaff/Movies.aspx">[Movies]</asp:HyperLink> &nbsp;
    <asp:HyperLink ID="HyperLink144" runat="server" NavigateUrl="~/TheatreStaff/Schedule.aspx" ForeColor="#FF9900">[Schedules]</asp:HyperLink>&nbsp;   
 <asp:HyperLink ID="HyperLink117" runat="server" NavigateUrl="~/TheatreStaff/Session.aspx" ForeColor="#FF6699">[Session Times]</asp:HyperLink>&nbsp;  
  <asp:HyperLink ID="HyperLink116" runat="server" NavigateUrl="~/TheatreStaff/SessionDates.aspx" ForeColor="#66FF66">[Session Date]</asp:HyperLink>&nbsp;    
 <asp:HyperLink ID="HyperLink115" runat="server" NavigateUrl="~/TheatreStaff/SpecialTickets.aspx" ForeColor="Aqua">[Specail Price]</asp:HyperLink>&nbsp;
 <asp:HyperLink ID="HyperLink107" runat="server" NavigateUrl="~/TheatreStaff/specialday.aspx" ForeColor="#CCFF33">[Special Ticket Pricing Days]</asp:HyperLink>&nbsp;  
    <asp:HyperLink ID="HyperLink6" runat="server" NavigateUrl="~/TheatreStaff/SalesReports.aspx" ForeColor="#CCFFFF">[Sales Report]</asp:HyperLink>&nbsp;  
            <asp:HyperLink ID="HyperLink11" runat="server" NavigateUrl="~/TheatreStaff/AddNewUser.aspx" ForeColor="#66FF99">[Add New User]</asp:HyperLink>&nbsp; 
  <hr />
 <h3><asp:Label ID="Label2" Text ="Schedule Maintenance" runat="server" CssClass="center" ForeColor="#FF9900" /></h3>       <br />
         <asp:BulletedList ID="BulletedList2"  CssClass="bullet" ForeColor="white" runat="server">
               <%--<asp:ListItem  Text="When you insert the release date, please folow the format: dd/mm/yyyy" />--%>
               <asp:ListItem Text="Click 'Select' to view more details" />
               <asp:ListItem Text="Click 'Edit' to view the update screen to update schedule details" />
               <asp:ListItem Text="Click 'Cancel' to return to the Schedule Maintenance section" />
               <asp:ListItem Text="Click 'Delete' to delete a schedule" />
               <asp:ListItem Text="Click 'New' to insert a new schedule" />
        </asp:BulletedList>
        <div class ="content1">
         <%--<h2><asp:Label ID="Label54" Text ="Add New Cinema" runat="server" /></h2>--%>
         <table >
            <tr >
                <td><h3><asp:Label ID="Label1" Text ="Maintain Schedules" Visible="false" runat="server" /></h3></td>
            </tr>
         </table> 
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
          <div class="column">
        <asp:GridView
            id="grdSchedule"
            DataSourceID="srcgrdSchedule"
            DataKeyNames="ScheduleId"
            AutoGenerateSelectButton="True"
            AutoGenerateColumns ="false" 
            SelectedRowStyle-CssClass="selectedRow"
            AllowPaging="true"
            Runat="server" Width="258px" >
            <Columns >
            <custom:DeleteButtonField CommandName="Delete" ConfirmText ="Are you sure that you want to delete this record?" />
                <asp:BoundField DataField ="ScheduleStartDate" 
                HeaderText ="Schedule Start Date" DataFormatString ="{0:d}"  />
                 <asp:BoundField DataField ="ScheduleEndDate" DataFormatString ="{0:d}" 
                HeaderText ="Schedule End Date"  />
            </Columns>
        </asp:GridView> 
       </div>
       
        <div class="column">
        <asp:DetailsView
            id="dtlSchedule"
            AutoGenerateEditButton="true"
            AutoGenerateInsertButton ="true"
            AllowPaging="false" AutoGenerateRows ="false"
            DataSourceID="srcSchedule"
            DataKeyNames="ScheduleId"
            Runat="server"  OnItemInserting ="btnOk_Click"  
            OnItemInserted ="dtlSchedule_ItemInserted" OnItemUpdated ="dtlSchedule_ItemUpdated"
            >
             <Fields >
                     <asp:TemplateField HeaderStyle-Font-Bold="true" HeaderText="Schedule Start Date">
                    <ItemTemplate>
                        <%# Eval("ScheduleStartDate","{0:d}")%> 
                    </ItemTemplate>
                    <EditItemTemplate >
                        <asp:TextBox ID="txtSDate" 
                         Text='<%# Bind("ScheduleStartDate","{0:d}") %>' 
                         runat="server" />
                          <asp:RequiredFieldValidator ID="reqScheduleStartDate" 
                        runat="server" 
                        ErrorMessage="(Required)" ControlToValidate ="txtSDate"/>
              <%--          <asp:CompareValidator ID="comScheduleStartDate"
                         runat="server" 
                         ErrorMessage="(Please enter a valid date in dd/mm/yyyy format)"
                         ControlToValidate="txtSDate" Type="Date" Operator="DataTypeCheck" />--%>
                         
                             <asp:RegularExpressionValidator 
                     ID="RegularExpressionValidator1I" 
                     ControlToValidate="txtSDate" 
                     runat="server" 
                     ErrorMessage="(Please enter a valid date in the dd/MM/yyyy format)"
                      ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d">
                      </asp:RegularExpressionValidator>
                      
                    </EditItemTemplate>
                  </asp:TemplateField> 
                  <asp:TemplateField HeaderStyle-Font-Bold="true" HeaderText="Schedule End Date">
                    <ItemTemplate>
                        <%# Eval("ScheduleEndDate", "{0:d}")%> 
                    </ItemTemplate>
                    <EditItemTemplate >
                        <asp:TextBox ID="txtEDate" 
                          Text='<%# Bind("ScheduleEndDate","{0:d}") %>' 
                          runat="server"/>
                        <asp:RequiredFieldValidator ID="reqScheduleEndDate" 
                        runat="server" 
                        ErrorMessage="(Required)" ControlToValidate ="txtEDate"/>
                     <%--   <asp:CompareValidator ID="comScheduleEndDate"
                         runat="server" 
                         ErrorMessage="(Please enter a valid date in dd/mm/yyyy format)"
                         ControlToValidate="txtEDate" Type="Date" Operator="DataTypeCheck" />--%>
                         
                            <asp:RegularExpressionValidator 
                     ID="RegularExpressionValidator2I" 
                     ControlToValidate="txtEDate" 
                     runat="server" 
                     ErrorMessage="(Please enter a valid date in the dd/MM/yyyy format)"
                      ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d">
                      </asp:RegularExpressionValidator>
                    </EditItemTemplate>
                </asp:TemplateField>
             </Fields>
       </asp:DetailsView>
            
            
        <asp:Label ID="lblId" runat="server" Visible="false" ></asp:Label>
        
        </div>
        </ContentTemplate>
            </asp:UpdatePanel>
      </div>
         <asp:SqlDataSource ID="srcgrdSchedule" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"         
        SelectCommand="SELECT Schedule.ScheduleId,Schedule.ScheduleStartDate,Schedule.ScheduleEndDate FROM 
          Schedule,Theatrestaff WHERE Schedule.TheatreId=TheatreStaff.TheatreId 
          AND TheatreStaff.TheatreStaffUserName=@username"
         DeleteCommand ="DELETE Schedule WHERE ScheduleId=@ScheduleId">
            <SelectParameters>
                <asp:Parameter  Type="String"  Name="username" />
            </SelectParameters>
        </asp:SqlDataSource>
             
        <asp:SqlDataSource ID="srcSchedule" runat="server" 
              ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
              SelectCommand="SELECT Schedule.ScheduleId,Schedule.ScheduleStartDate,Schedule.ScheduleEndDate FROM 
              Schedule,Theatrestaff WHERE Schedule.TheatreId=TheatreStaff.TheatreId 
              AND TheatreStaff.TheatreStaffUserName=@username AND Schedule.ScheduleId=@ScheduleId" 
              InsertCommand  ="INSERT INTO Schedule(TheatreId,ScheduleStartDate,ScheduleEndDate)
        Values (@TheatreId,@ScheduleStartDate,@ScheduleEndDate) "
             UpdateCommand ="UPDATE Schedule SET ScheduleStartDate=@ScheduleStartDate,
             ScheduleEndDate=@ScheduleEndDate WHERE ScheduleId=@ScheduleId"  >
        <SelectParameters>
              <asp:Parameter Name ="username" Type ="string"/> 
              <asp:ControlParameter Name ="ScheduleId" ControlID ="grdSchedule" />
        </SelectParameters>
        <InsertParameters >
               <asp:Parameter Name="TheatreId" DbType="Int32"  />
               <asp:Parameter Name ="ScheduleStartDate" DbType="Date" />
               <asp:Parameter Name ="ScheduleEndDate" DbType="Date" />
        </InsertParameters>
        <UpdateParameters >
               <asp:Parameter Name ="ScheduleStartDate" DbType="Date" />
               <asp:Parameter Name ="ScheduleEndDate" DbType="Date" />
               <asp:Parameter Name ="ScheduleId" DbType ="Int32" />
        </UpdateParameters>
        </asp:SqlDataSource> 
   
       <br /> <br /> <br /> <br />
   <table align="left"  cellpadding="15" ><tr><td>Copyright@2012 MovieTix</td><td><asp:HyperLink ID="HyperLink8"  CssClass="footer" NavigateUrl="~/Default.aspx" runat="server">Homepage</asp:HyperLink></td><td><asp:HyperLink ID="HyperLink9"  CssClass="footer" NavigateUrl="~/TheatreStaff/Session.aspx" runat="server">Session</asp:HyperLink></td><td><asp:HyperLink ID="HyperLink10"  CssClass="footer" NavigateUrl="~/TheatreStaff/Movies.aspx" runat="server">Movies</asp:HyperLink></td><td><asp:HyperLink ID="HyperLink12"  CssClass="footer" NavigateUrl="~/register.aspx" runat="server">Register</asp:HyperLink></td><td><asp:HyperLink ID="HyperLink13"  CssClass="footer" NavigateUrl="~/Login.aspx" runat="server">Log In</asp:HyperLink></td></tr></table>
      </div> 
</form>
</body>
</html>